package org.skavookie.linalg

/**
 * Created by IntelliJ IDEA.
 * User: joshua
 * Date: 9/20/11
 * Time: 7:33 AM
 * To change this template use File | Settings | File Templates.
 */

/**
 * A base class for maths vectors based on doubles.
 */
case class Vec(vector: Double*) {

  /** The length as in number of terms */
  lazy val length: Int = vector length

  /** Norm: sqrt(this dot this) */
  lazy val norm: Double = math.sqrt(this dot this)

  /** The negate of one */
  lazy val negate: Vec = Vec((vector map {-_}): _*)

  /** Dot rule: x dot y = x1*y1 + x2*y2 + ... */
  def dot(o: Vec): Double = (vector zip o.vector).map{case (a,b) => a*b}.foldLeft(0D)((a,b) => a+b)

  /** Parallelogram */
  def +(o: Vec): Vec = Vec((vector zip o.vector).map{case (a,b) => a+b}: _*)

  /** Inverters Parallelogram */
  def -(o: Vec): Vec = this+o.negate

  /** Scale produced */
  def *(s: Double): Vec = Vec((vector map { s*_ }): _*)

}
